using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_MoneyPanel : UIBaseNode
    {

        #region Template Generate,don't modify
        protected partial class UIB_UIN_MoneyPanel
        {
            #region ObjectBinding Generate 
            public GameObject moneyMould { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<UnityEngine.GameObject>("moneyMould", out var __tbv0);
                this.moneyMould = __tbv0;
            }

            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields & properties
        private ListScrollAdapter<UIN_OneMoney> _csListMoney = null;

        private int[] _cids = null;

        protected UIB_UIN_MoneyPanel ui { get; set; }
        #endregion
        protected override void BeforeInit()
        {
            ui = new UIB_UIN_MoneyPanel();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this._csListMoney = this.InitListScroll<UIN_OneMoney>(this.ui.moneyMould, this.OnItemChanged);
        }

        private void OnItemChanged(UIN_OneMoney item, int index)
        {
            item.Show(this._cids[index]);
        }

        public void Show(string uiName)
        {
            if (uiName == null)
            {
                this.Hide();
                return;
            }
            int[] cids = APIUIConst.GetItemCids4MoneyAsset(uiName);
            this.Show(cids);
        }

        public void Show(int[] cids)
        {
            if (cids == null || cids.Length == 0)
            {
                this.Hide();
                return;
            }
            this.Show();
            this._cids = cids;
            this._csListMoney.RefillCells(cids.Length);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        protected override void OnDispose()
        {

        }
    }
}
